package com.epam.task.thread;

import org.apache.log4j.Logger;

import java.util.Random;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;

/**
 * Created with IntelliJ IDEA.
 * User: zhunusbekova.arailym
 * Date: 04.09.13
 * Time: 15:26
 * To change this template use File | Settings | File Templates.
 */
public class OperatorPool {
    public static final Logger logger = Logger.getLogger(OperatorPool.class);
    private Random random = new Random();

    private boolean isFree = true;
    private BlockingQueue<Operator> operatorsQueue;

    OperatorPool(int staffSize) throws ClassNotFoundException {
        operatorsQueue = new ArrayBlockingQueue<Operator>(staffSize);
        for (int i = 0; i < staffSize; i++) {
            Operator operator = new Operator(random.nextInt(10) + 1);
            operatorsQueue.offer(operator);
        }
    }

    public Operator takeOperator() {
        Operator operator = null;
        try {
            operator = operatorsQueue.take();
        } catch (InterruptedException e) {
        }
        return operator;
    }

    public void addOperator(Operator operator) {
        operatorsQueue.add(operator);
    }

    public void removeOperator(Operator operator) {
        operatorsQueue.remove(operator);
    }
}
